<template>
	<div class="oldman_data_part">
		<div class="filter_part">
			<AplidForm ref="query" v-bind="serchConfig" v-model="searchModel"></AplidForm>
		</div>
		<div class="btn_part">
			<button @click="toReset">重置</button>
			<button @click="toSearch">搜索</button>
		</div>
		<div class="table_part">
			<table cellspacing="0" width="100%" style="border-spacing: 0 10px; border-collapse: separate; border-radius: 20px">
				<tr style="background-color: #4da5ffaa; height: 50px">
					<th>所属区域</th>
					<th>机构名称</th>
					<th>统一社会信用代码</th>
					<th>联系人</th>
					<th>联系方式</th>
					<th>机构类型</th>
					<th>机构评定星级</th>
					<th>是否备案</th>
					<!-- <th>床位总数</th> -->
					<th>操作</th>
				</tr>
			</table>
			<div class="two_table">
				<el-empty v-if="list.length == 0" description="暂无数据" />
				<table cellspacing="0" width="100%" style="border-spacing: 0 10px">
					<tr v-for="item in list" :key="item.id" style="background-color: #a5d1ffaa; height: 50px">
						<td>{{ item.areaName || '/'}}</td>
						<td>{{ item.organizationName || '/'}}</td>
						<td>{{ item.creditCode || '/'}}</td>
						<td>{{ item.burdenUserName || '/'}}</td>
						<td>{{ plusXing(item.burdenUserPhone) || '/'}}</td>
						<td>{{ item.organizationTypeLabel || '/'}}</td>
						<td>{{ item.organizationLevelLabel|| '/' }}</td>
						<td>{{ item.filingFlagLabel || '/'}}</td>
						<!-- <td>{{ item.bedTotalNum }}</td> -->
						<td>
							<button style="background-color: #0057a1; color: white; border: none; padding: 3px" @click="openDialog(item)">查看档案</button>
						</td>
					</tr>
				</table>
			</div>
		</div>
		<div class="the_footer_part">
			<AplidPaginate class="pageinate mt10" v-bind="pageReac" layout="prev, pager,next" @change="onPageChange" />
		</div>

		<!-- 打开弹窗 -->
		<aplid-dialog
			whickComm="Archives"
			v-model="dialogVisible"
			width="80%"
			:customeHeader="customeHeader"
			title="档案信息"
			append-to-body
			:close-on-click-modal="false"
			pageName="养老机构"
			:model="rowData"
		>
			<DetailPart
				v-if="dialogVisible"
				@refresh="handleRefresh"
				@refreshPage="handleRefreshPage"
				@rechange="handleOperate"
				:nowRowData="rowData"
				:isBlockchain="true"
			></DetailPart>
		</aplid-dialog>
	</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { getAreaObj } from '@/utils/util'
import DetailPart from './archival/index.vue'
import apiMod from '@/apiMod/index'
import { plusXing } from '@/utils/util'
import AplidPaginate from '@/components/AplidCrud/src/AplidPaginate'
import  {AplidAreaSelect}  from '@/components/AplidCrud'
import dialogCard from '@/components/AplidDialog/components/Card2.vue'
import { useCommonStore } from '@/stores/common'
let {setGloablParams} = useCommonStore()

let query = ref()
let props = defineProps({
	nowRowData:{
		type:Object,
		default:() =>({})
	}
})
let list: any = ref([])
let searchModel: any = ref({})
let serchConfig = {
	showBtn: false,
	inline: true,
	labelPosition: 'right',
	labelWidth: 140,
	column: [
	{
			label: '信用代码',
			prop: 'creditCode',
			type: 'input',
			span: 6,
		},
		{
			label: '机构名称',
			prop: 'organizationName',
			type: 'input',
			span: 6,
		},
		{
			label: '联系人',
			prop: 'burdenUserName',
			type: 'input',
			span: 6,
		},
		{
			label: '联系方式',
			prop: 'burdenUserPhone',
			type: 'input',
			span: 6,
		},
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			teleported: false,
			span: 6,
		},
		{
			label: '机构类型',
			prop: 'organizationType',
			type: 'remoteSelect',
			code: 'ORG_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			teleported: false,
			multiple: false,
			span: 6,
		},
		{
			label: '机构星级',
			prop: 'organizationLevel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			teleported: false,
			multiple: false,
			span: 6,
		},
		{
			label: '运营状态',
			prop: 'operateStatus',
			changeField: true,
			type: 'remoteSelect',
			code: 'ORG_OPERATE_STATUS',
			api: 'getDictItemList',
			filterKey: 'value',
			teleported: false,
			multiple: false,
			span: 6,
		},
		// {
		// 	label: '探访类别',
		// 	prop: '',
		// 	span: 6,
		// 	clearable: true,
		// },
	],
}
let rowData: any = ref({})
const onPageChange = (data) =>{
	pageReac.value = data
	getDataList()
}
const customeHeader= {
			type: 'CardOne',
			title: 'organizationName',
			avatar: 'organizationLogo',
			tipList: [{ prop: 'operateStatusLabel', type: 'tip-success', label: '运营状态' }],
			tagList: [{ prop: 'organizationTypeLabel', custome: 'tag', type: 'success', label: '机构类型' }],
			menuBtn: [
				{
					icon: 'delete',
					label: '删除服务组织',
					type: 'danger',
					operate: 'delete',
					auth: 'view_dpServiceOrgBase_del',
					text: false,
					show: true,
					plain: true,
				},
			],
}

let dialogVisible = ref(false)
const openDialog = (item) => {
	let params = {
		key:item.creditCode,
		code:3013
	}
	apiMod.view_blockchainBackupGeneral_queryBlockchainInfo(params).then((res) => {
		res.data.onBlockchainFlag = 1
		// 处理一下区域
		let obj:any = getAreaObj(res.data,'','set')
		let newObj:any = getAreaObj(res.data,'now','set')
		res.data.areas = obj.areaIds
		res.data.areas_name = obj.names
		res.data.nowAreas =newObj.areaIds
		res.data.nowAreasNames =newObj.names
		rowData.value = res.data
		dialogVisible.value = true
	})
}
let idCard = ref(undefined)
let pageReac = ref({
	current: 1,
	size: 10,
	total: 0,
})
const getDataList = () => {
	// 处理一下搜索数据
	let ceArea: any = []
	if (searchModel.value.areas) {
		ceArea = getAreaObj(searchModel.value.areas, '')
		searchModel.value.areas = undefined
	}

	let params = {
		idCard: idCard.value,
		...searchModel.value,
		...ceArea,
		pageParaPO: pageReac.value,
	}
	apiMod.view_bcServiceOrgBase_page(params).then((res) => {
		if (res.code == 0) {
			pageReac.value.total = res.data.total
			list.value = res.data.records
		}
	})
}
const handleRefresh = (query, visible = false) => {
	dialogVisible.value = visible
	//   nextTick(() => {
	//     crud.value.refreshChange(query)
	//   })
}
const handleRefreshPage = () => {
	//   nextTick(() => {
	//     crud.value.refreshChange({}, true)
	//   })
}
const handleOperate = (type, row, title) => {
	//   nextTick(() => {
	//     crud.value.handleOperate(type, row, title)
	//   })
}
getDataList()
// 去重置
const toReset = () =>{
	query.value.onReset()
	setGloablParams({})
	searchModel.value = {}
	getDataList()
}
// 去搜索
const toSearch = () =>{
	console.log('fffff')
	getDataList()
}
</script>
<style lang="scss" scoped>
@import '../style.scss'
</style>
